﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using QuanLyDuocPham.Controllers.QuanLyHeThong.DanhMuc;
using QuanLyDuocPham.Controllers.QuanLyHeThong.NhapXuat;

namespace QuanLyDuocPham.View.QuanLyHeThong.NhapXuat
{
    /// <summary>
    /// Interaction logic for DDHXUAT_Add_View.xaml
    /// </summary>
    public partial class DDHXUAT_Add_View : Window
    {
        public DDHXUAT_Add_View()
        {
            InitializeComponent();
        }
        string ma_xuat;
        public string _ma_xuat
        {
            set
            {
                ma_xuat = value;
            }
        }
        public delegate void added();
        public added done;
        NHANVIEN_Control nvctrl = new NHANVIEN_Control();
        KHACHHANG_Control khctrl = new KHACHHANG_Control();
        DDHXUAT_Control xctrl = new DDHXUAT_Control();
        DDH_XUAT_CT_Control xctctrl = new DDH_XUAT_CT_Control();
        KHO_Control khoctrl = new KHO_Control();        
        NHATHUOC_Control ntctrl = new NHATHUOC_Control();
        QUAY_Control quayctrl = new QUAY_Control();
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            ma_xuat = xctrl.loadID_moi();
            nvctrl.loadComboBox(cmbNhanVien);
            khctrl.loadComboBox(cmbKhachHang);
            khoctrl.loadComboBox(cmbKho);
            ntctrl.loadComboBox(cmbNhaThuoc);
            quayctrl.loadComboBox(cmbQuay);
            additemcmbTinhTrang();
            btnCloseNHAPCT.IsEnabled = false;
        }
        private void additemcmbTinhTrang()
        {

            cmbTinhTrang.Items.Add("Chưa giao, Đã thanh toán");
            cmbTinhTrang.Items.Add("Chưa giao, Chưa thanh toán");
            cmbTinhTrang.Items.Add("Đã giao, Chưa thanh toán");
            cmbTinhTrang.Items.Add("Đã giao, Đã thanh toán");
            cmbTinhTrang.Items.Add("Bị trả lại");
        }
        UIElement ui;
        private void hideNHAPHANG(Boolean isenable)
        {

            cmbKhachHang.IsEnabled = isenable;
            cmbKho.IsEnabled = isenable;
            cmbLoaiHD.IsEnabled = isenable;
            cmbNhanVien.IsEnabled = isenable;
            cmbNhaThuoc.IsEnabled = isenable;
            cmbQuay.IsEnabled = isenable;
            cmbTinhTrang.IsEnabled = isenable;
            txtDaTT.IsEnabled = isenable;
            chbCo_HD.IsEnabled = isenable;
            dtHanTT.IsEnabled = isenable;
            dtpNgayGiao.IsEnabled = isenable;
            dtpNgayNhap.IsEnabled = isenable;
                
        }
        private void clearNHAPHANG()
        {
            ma_xuat = xctrl.loadID_moi();

            cmbTinhTrang.SelectedItem = null;
            cmbQuay.SelectedItem = null;
            cmbNhaThuoc.SelectedItem = null;
            cmbNhanVien.SelectedItem = null;
            cmbLoaiHD.SelectedItem = null;
            cmbKho.SelectedItem = null;
            cmbKhachHang.SelectedItem = null;
            txtDaTT.Clear();
            dtpNgayNhap.SelectedDate = DateTime.Now;
            dtpNgayGiao.SelectedDate = DateTime.Now;
            dtpNgayNhap.SelectedDate = DateTime.Now;
            chbCo_HD.IsChecked = false;
        }

        private void btnok_Click_1(object sender, RoutedEventArgs e)
        {
            btnok.IsEnabled = false;
            xctrl.addData(ma_xuat, cmbKho, cmbKhachHang, cmbNhanVien, cmbNhaThuoc, cmbQuay, dtpNgayNhap, dtpNgayGiao, cmbTinhTrang, cmbLoaiHD, chbCo_HD, chbDa_Xoa, dtHanTT, txtDaTT);
            if (done != null)
            {
                done();
            }
            hideNHAPHANG(false);
            Controllers.UC.QuanLyHeThong.NhapXuat.UC_DDHXUAT_CT_View ul = new Controllers.UC.QuanLyHeThong.NhapXuat.UC_DDHXUAT_CT_View();
            ul._ma_xuat = ma_xuat;
            ul._ma_kho = ((KHO_Get_ListResult)cmbKho.SelectedItem).MA_KHO;

            ul._is_edit = false;
            ul.Margin = new Thickness(0, 0, 0, 0);
            MainFrame.Children.Add(ul);
            ui = ul;
        }

        private void btnClearNHAPHANG_Click(object sender, RoutedEventArgs e)
        {
            clearNHAPHANG();

        }

        private void btnCloseNHAPCT_Click(object sender, RoutedEventArgs e)
        {
            clearNHAPHANG();
            MainFrame.Children.Remove(ui);
            xctctrl.clearTemp2();
            btnok.IsEnabled = true;
        }

        private void btnClose_Click(object sender, RoutedEventArgs e)
        {
            this.Close();

        }

        private void txtDaTT_TextChanged(object sender, TextChangedEventArgs e)
        {
            if (xctctrl.TongTien(ma_xuat) == decimal.Parse(txtDaTT.Text))
            {
                chbDaTToan.IsChecked = true;
            }
            else chbDaTToan.IsChecked = false;
        }
    }
}
